﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NetPE.Core.Metadata;
using System.Reflection;

namespace NetPE
{
    public partial class MetadataTokenEditor : BaseEditor
    {
        public MetadataTokenEditor(MetadataToken tkn)
        {
            InitializeComponent();
            Object = tkn;
        }

        bool refreshing = false;
        protected override void RefreshData()
        {
            refreshing = true;
            comboBox1.SelectedItem = (Object as MetadataToken).Type.ToString();
            numericUpDown1.Value = (Object as MetadataToken).Index;
            refreshing = false;
        }

        void valChanged(object sender, EventArgs e)
        {
            if (refreshing) return;
            try
            {
                (Object as MetadataToken).Type = (MetadataTokenType)Enum.Parse(typeof(MetadataTokenType), comboBox1.SelectedItem.ToString());
                (Object as MetadataToken).Index = (uint)numericUpDown1.Value;
                if (ValueChanged != null)
                    ValueChanged(this, new EventArgs());
            }
            catch { }
        }

        public event EventHandler ValueChanged;
    }
}
